/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import dao.ConexaoBanco;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 *
 * @author deivide
 */
public class AlterarFilme extends javax.swing.JFrame {

    //private static final AlterarFilme instancia = new AlterarFilme();
    private File escolhido;
    private File destino;
    private String capa;
    private String resultado[][];
    private static String diretores[];
    private static String diretores_dados[];
    private static int tamanho_diretores;
    private static String atores[];
    private static String atores_dados[];
    private static int tamanho_atores;
    private static String generos[];
    private static String generos_dados[];
    private static int tamanho_generos;
    private String resultado_diretores[][];
    private String resultado_atores[][];
    private String resultado_generos[][];
    private boolean bool = false;
    
    private ArrayList<String> lista_diretores = new ArrayList<>();
    private ArrayList<String> lista_atores = new ArrayList<>();
    private ArrayList<String> lista_generos = new ArrayList<>();
    

    /**
     * Creates new form AlterarFilme
     */
    public AlterarFilme() {
        initComponents();
        this.capa = "";
        this.setVisible(true);
        this.setLocationRelativeTo(null);
        inicializaComponentes();

    }
//    
//    public static AlterarFilme getInstancia(){
//        return AlterarFilme.instancia;
//    }

    public void inicializaComponentes() {
        String select[] = {"filme.nome as nomefilme", "filme.categoria as nomecategoria", "genero.nome as generonome", "duracao", "diretor.nome as diretornome", "ano_lancamento", "sinopse", "capa", "valor", "traducao","ator.nome as nomeator"};
        String from[] = {"locadora.filme", "locadora.filme_diretor", "locadora.diretor", "locadora.filme_ator", "locadora.ator",
            "locadora.preco", "locadora.filme_genero", "locadora.genero"};
        String on[] = {"filme.id_filme=filme_diretor.id_filme", "filme_diretor.id_diretor=diretor.id_diretor",
            "filme_ator.id_filme=filme.id_filme", "filme_ator.id_ator=ator.id_ator", "preco.categoria=filme.categoria",
            "filme.id_filme=filme_genero.id_filme", "filme_genero.id_genero=genero.id_genero"};
        String where[] = {"filme.id_filme = " + (String) Filme.getInstancia().getTabela_Buscar().
            getValueAt(Filme.getInstancia().getTabela_Buscar().getSelectedRow(), 0)};

        System.out.println("ID DO FILME: " + where[0]);
        //faz a busca dos dados do cliente selecionado
        String resultado_consulta[][] = ConexaoBanco.getInstacia().Select(select, from, on, where, "FULL OUTER JOIN");

        //coloca os dados nas labels
        this.nome.setText(resultado_consulta[0][0]);
        //this.categoria.setText(resultado[0][1]);
        //this.genero.setText(resultado[0][2]);
        this.duracao.setText(resultado_consulta[0][3]);
        //this.diretor.setText(resultado[0][4]);
        this.ano_lancamento.setText(resultado_consulta[0][5]);
        this.sinopse.setText(resultado_consulta[0][6]);
        //this.capa.setText(resultado[0][7]);
        //this.preco.setText(resultado[0][8]);
        this.traducao.setText(resultado_consulta[0][9]);

        this.capa = resultado_consulta[0][7];
        //inicializando as Jlists
//        String select_list[] = {"nome"};
//        String from_list[] = {"locadora.diretor"};
//        String where_list[] = {"nome = "+(String)Filme.getInstancia().getTabela_Buscar().
//                getValueAt(Filme.getInstancia().getTabela_Buscar().getSelectedRow(), 0)};
//        String resultado_jlist [][] = ConexaoBanco.getInstacia().Select(select_list, from_list, null, where_list, "");
        String data[] = new String[resultado_consulta.length];
        String data_ator[] = new String[resultado_consulta.length];
        String data_genero[] = new String[resultado_consulta.length];
        ArrayList<String> check = new ArrayList<>();
        ArrayList<String> check_ator = new ArrayList<>();
        ArrayList<String> check_genero = new ArrayList<>();

        for (int i = 0; i < resultado_consulta.length; i++) {
            if (!check.contains(resultado_consulta[i][4])) {
                data[i] = resultado_consulta[i][4];
                check.add(resultado_consulta[i][4]);
                this.lista_diretor.setListData(data);
            }

            if (!check_ator.contains(resultado_consulta[i][10])) {
                    data_ator[i] = resultado_consulta[i][10];
                    check_ator.add(resultado_consulta[i][10]);
                    this.lista_ator.setListData(data_ator);

            }
            
            if (!check_genero.contains(resultado_consulta[i][2])) {
                    data_genero[i] = resultado_consulta[i][2];
                    check_genero.add(resultado_consulta[i][2]);
                    this.lista_genero.setListData(data_genero);

            }
        }



        initCombobox();

    }

    public void initCombobox() {
        String select[] = {"nome", "id_ator"};
        String from[] = {"locadora.ator"};
        String on = "";
        String where[] = null;
        resultado_atores = ConexaoBanco.getInstacia().Select(select, from, null, where, "JOIN");
        atores = new String[resultado_atores.length];
        atores_dados = new String[resultado_atores.length];
        for (int i = 0; i < resultado_atores.length; i++) {
            this.ator.addItem(resultado_atores[i][0].toString());
            atores[i] = resultado_atores[i][1];
            //Filme.atores_dados[i] = resultado_atores[i][0];
        }
        //tamanho_atores = r.length;
        select[0] = "nome";
        select[1] = "id_diretor";
        from[0] = "locadora.diretor";
        on = "";
        where = null;
        resultado_diretores = ConexaoBanco.getInstacia().Select(select, from, null, where, " JOIN ");

        // tamanho_diretores = r.length;
        diretores = new String[resultado_diretores.length];
        diretores_dados = new String[resultado_diretores.length];
        for (int i = 0; i < resultado_diretores.length; i++) {
            this.diretor.addItem(resultado_diretores[i][0].toString());
            diretores[i] = resultado_diretores[i][1];
            //Filme.diretores_dados[i] = resultado_atores[i][0];
        }

        select[0] = "nome";
        select[1] = "id_genero";
        from[0] = "locadora.genero";
        on = "";
        where = null;
        resultado_generos = ConexaoBanco.getInstacia().Select(select, from, null, where, " JOIN ");

        //tamanho_generos = r.length;
        generos = new String[resultado_generos.length];
        generos_dados = new String[resultado_generos.length];
        for (int i = 0; i < resultado_generos.length; i++) {
            this.genero.addItem(resultado_generos[i][0].toString());
            generos[i] = resultado_generos[i][1];
            //Filme.generos_dados[i] = resultado_atores[i][0];
        }

        System.out.println("adicionou!!");

        ArrayList<String> aux = ConexaoBanco.getInstacia().getAllCategoria();
        for (int i = 0; i < aux.size(); i++) {

            categoria.addItem(aux.get(i));

        }



    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        nome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        duracao = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        categoria = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        diretor = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        ator = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        genero = new javax.swing.JComboBox();
        jScrollPane5 = new javax.swing.JScrollPane();
        lista_diretor = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        lista_ator = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        lista_genero = new javax.swing.JList();
        adicionar_diretor = new javax.swing.JButton();
        adicionar_ator = new javax.swing.JButton();
        adicionar_genero = new javax.swing.JButton();
        traducao = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        ano_lancamento = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        sinopse = new javax.swing.JTextArea();
        jButton3 = new javax.swing.JButton();
        adicionar_diretor1 = new javax.swing.JButton();
        adicionar_ator1 = new javax.swing.JButton();
        adicionar_genero1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Filme"));

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel2.setText("NOME");

        jLabel4.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel4.setText("DURACAO");

        jLabel5.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel5.setText("CAPA");

        jButton2.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jButton2.setText("SELECIONAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        categoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categoriaActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel6.setText("CATEGORIA");

        diretor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                diretorActionPerformed(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel14.setText("DIRETOR(ES)");

        jLabel13.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel13.setText("ATOR(ES)");

        ator.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atorActionPerformed(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel12.setText("GENERO(S)");

        genero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                generoActionPerformed(evt);
            }
        });

        jScrollPane5.setViewportView(lista_diretor);

        jScrollPane4.setViewportView(lista_ator);

        jScrollPane3.setViewportView(lista_genero);

        adicionar_diretor.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        adicionar_diretor.setText("ADICIONAR");
        adicionar_diretor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionar_diretorActionPerformed(evt);
            }
        });

        adicionar_ator.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        adicionar_ator.setText("ADICIONAR");
        adicionar_ator.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionar_atorActionPerformed(evt);
            }
        });

        adicionar_genero.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        adicionar_genero.setText("ADICIONAR");
        adicionar_genero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionar_generoActionPerformed(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel18.setText("Tradução");

        jLabel15.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel15.setText("Ano de Lançamento");

        jLabel3.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel3.setText("SINOPSE");

        sinopse.setColumns(20);
        sinopse.setRows(5);
        jScrollPane2.setViewportView(sinopse);

        jButton3.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jButton3.setText("CONFIRMAR");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        adicionar_diretor1.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        adicionar_diretor1.setText("REMOVER");
        adicionar_diretor1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionar_diretor1ActionPerformed(evt);
            }
        });

        adicionar_ator1.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        adicionar_ator1.setText("REMOVER");
        adicionar_ator1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionar_ator1ActionPerformed(evt);
            }
        });

        adicionar_genero1.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        adicionar_genero1.setText("REMOVER");
        adicionar_genero1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionar_genero1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(18, 18, 18)
                        .addComponent(ano_lancamento, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel18)
                        .addGap(18, 18, 18)
                        .addComponent(traducao, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(adicionar_diretor1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(adicionar_diretor))
                        .addGap(83, 83, 83)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(adicionar_ator1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(adicionar_ator, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 83, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(adicionar_genero, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(adicionar_genero1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(63, 63, 63))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(29, 29, 29)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addGap(27, 27, 27)
                            .addComponent(jScrollPane2))
                        .addComponent(jButton3)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel4)
                                .addComponent(jLabel5)
                                .addComponent(jLabel2))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jButton2)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel6)
                                    .addGap(18, 18, 18)
                                    .addComponent(categoria, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(duracao, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addGap(30, 30, 30)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(diretor, 0, 114, Short.MAX_VALUE)
                                .addComponent(jLabel14)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 86, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel12)
                                    .addGap(78, 78, 78))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(ator, 0, 114, Short.MAX_VALUE)
                                        .addComponent(jLabel13)
                                        .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE))
                                    .addGap(73, 73, 73)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(genero, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(46, 46, 46)))))
                    .addContainerGap(29, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(260, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(adicionar_diretor)
                    .addComponent(adicionar_ator)
                    .addComponent(adicionar_genero))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(adicionar_diretor1)
                    .addComponent(adicionar_ator1)
                    .addComponent(adicionar_genero1))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel18)
                        .addComponent(traducao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel15)
                        .addComponent(ano_lancamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(150, 150, 150))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(duracao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jButton2)
                        .addComponent(jLabel6)
                        .addComponent(categoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(11, 11, 11)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(genero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGap(24, 24, 24)
                                    .addComponent(ator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel14)
                                        .addComponent(jLabel13))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(diretor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(0, 98, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButton3)
                    .addContainerGap()))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        //Seleciona o Local onde deseja Salvar
        JFileChooser arquivo = new JFileChooser();
        FileFilter filter = new FileNameExtensionFilter("imagens", "png", "jpg", "gif");
        arquivo.setFileFilter(filter);
        int retorno = arquivo.showOpenDialog(null);

        if (retorno == JFileChooser.APPROVE_OPTION) {
            capa = arquivo.getSelectedFile().getAbsolutePath();
            this.escolhido = new File(capa);
            bool=true;
            System.out.println(capa);
        } else {
            System.out.println("Erro ao abrir a janela");
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void categoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categoriaActionPerformed
        // TODO add your handling code here:
        //System.out.println("ACIONOU!!");
        //String valor = ConexaoBanco.getInstacia().getValorCategoria(this.categoria.getSelectedItem().toString());
        // this.preco_label.setText("PREÇO R$ "+valor);
    }//GEN-LAST:event_categoriaActionPerformed

    private void diretorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diretorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_diretorActionPerformed

    private void atorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_atorActionPerformed

    private void generoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_generoActionPerformed

    private void adicionar_diretorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionar_diretorActionPerformed
        // TODO add your handling code here:
        //Filme.diretores[tamanho_diretores] = this.resultado_diretores[tamanho_diretores][1];
        diretores_dados[tamanho_diretores] = (String) this.diretor.getSelectedItem();

        if (this.diretor.getSelectedItem() != null) {
            this.lista_diretor.setListData(diretores_dados);
            this.lista_diretores.add((String) this.diretor.getSelectedItem());
        }
        //tamanho_diretores++;
        tamanho_diretores = (tamanho_diretores + 1) % diretores.length;
    }//GEN-LAST:event_adicionar_diretorActionPerformed

    private void adicionar_atorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionar_atorActionPerformed
        // TODO add your handling code here:
        atores_dados[tamanho_atores] = (String) this.ator.getSelectedItem();
        if (this.ator.getSelectedItem() != null) {
            this.lista_ator.setListData(atores_dados);
            this.lista_atores.add((String) this.ator.getSelectedItem());
        }
        tamanho_atores = (tamanho_atores + 1) % atores.length;
        //tamanho_atores++;
    }//GEN-LAST:event_adicionar_atorActionPerformed

    private void adicionar_generoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionar_generoActionPerformed
        // TODO add your handling code here:
        generos_dados[tamanho_generos] = (String) this.genero.getSelectedItem();
        if (this.genero.getSelectedItem() != null) {
            this.lista_genero.setListData(generos_dados);
             this.lista_generos.add((String) this.genero.getSelectedItem());
        }
        tamanho_generos = (tamanho_generos + 1) % generos.length;

    }//GEN-LAST:event_adicionar_generoActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        //primeiro deve-se fazer a consulta para verificar qual que é o id da
        //categoria para depois fazer a inserção do filme

        if (bool) {
            try {
                //JOptionPane.showMessageDialog(null, capa);
                String capa_destinho = "capa/" + escolhido.getName();
                this.destino = new File(capa_destinho);
                if (destino.createNewFile()) {
                    System.out.println("criou");
                    Filme.copyFile(escolhido, destino);

                } else {
                    System.out.println("erro");
                }
                //FileWriter f = new FileWriter(new File(capa));
                
                this.capa = capa_destinho;

            } catch (IOException ex) {
                Logger.getLogger(Filme.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        System.out.println(this.categoria.getSelectedItem().toString());

        //cadastrar filme
        //ConexaoBanco.getInstacia().cadastrarFilme(this.nome.getText(),
        //      this.duracao.getText(), this.capa, this.sinopse.getText(), this.categoria.getSelectedItem().toString());
        String into_values[] = {"nome", "duracao", "capa", "sinopse", "categoria", "ano_lancamento", "traducao"};
        String values[] = {this.nome.getText(), this.duracao.getText(), this.capa, this.sinopse.getText(),
            this.categoria.getSelectedItem().toString(), this.ano_lancamento.getText(), this.traducao.getText()};
        ConexaoBanco.getInstacia().Inserir("locadora", "filme", into_values, values);

        //pega o id do filme que acabou de ser inserido
        String select[] = {"id_filme"};
        String from[] = {"locadora.filme"};
        String where[] = {"nome = '" + this.nome.getText() + "'", "duracao = '" + this.duracao.getText() + "'"};
        String getidfilme[][] = ConexaoBanco.getInstacia().Select(select, from, null, where, "JOIN");
        System.out.println("IDFILME " + getidfilme[0][0]);

        //insere os dados referentes aos diretores
        String l_diretor[] = {"id_diretor", "id_filme"};
        String select_d[] = {"id_diretor"};
        String from_d[] = {"locadora.diretor"};
        
        //insercao na tabela filme_diretor
        for (int i = 0; i < this.lista_diretores.size(); i++) {
            System.out.println("NOME DOS DIRETORES: "+this.lista_diretores.get(i));
            String where_d[] = {"nome = '" + (String)this.lista_diretores.get(i)+"'"};        
            String r_diretor[][] = ConexaoBanco.getInstacia().Select(select_d, from_d, null, where_d, "");
            
            String nomes[] = {r_diretor[0][0], getidfilme[0][0]};
            ConexaoBanco.getInstacia().Inserir("locadora", "filme_diretor", l_diretor, nomes);

        }


        //insere os dados referentes aos atores
        String l_ator[] = {"id_ator", "id_filme"};
        String select_a[] = {"id_ator"};
        String from_a[] = {"locadora.ator"};
        
        //insercao na tabela filme_ator
        for (int i = 0; i < this.lista_atores.size(); i++) {
            String where_a[] = {"nome = '" + (String)this.lista_atores.get(i)+"'"};        
            String r_ator[][] = ConexaoBanco.getInstacia().Select(select_a, from_a, null, where_a, "");
            String nomes[] = {r_ator[0][0], getidfilme[0][0]};
            ConexaoBanco.getInstacia().Inserir("locadora", "filme_ator", l_ator, nomes);
        }


        //insere os dados referentes aos generos
        String l_genero[] = {"id_genero", "id_filme"};
        String select_g[] = {"id_genero"};
        String from_g[] = {"locadora.genero"};
        
        //insercao na tabela filme_ator
        for (int i = 0; i < this.lista_generos.size(); i++) {
            System.out.println("");
            System.out.println("GENEROS: "+this.lista_generos.get(i));
            String where_g[] = {"nome = '" + (String)this.lista_generos.get(i)+"'"};        
            String r_genero[][] = ConexaoBanco.getInstacia().Select(select_g, from_g, null, where_g, "");
            String nomes[] = {r_genero[0][0], getidfilme[0][0]};
            ConexaoBanco.getInstacia().Inserir("locadora", "filme_genero", l_genero, nomes);

        }
//        
//        String where_delete[]={"id_filme = "+ (String) Filme.getInstancia().getTabela_Buscar().
//            getValueAt(Filme.getInstancia().getTabela_Buscar().getSelectedRow(), 0)};
//        ConexaoBanco.getInstacia().delete("locadora.filme", where_delete);

    }//GEN-LAST:event_jButton3ActionPerformed

    private void adicionar_diretor1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionar_diretor1ActionPerformed
        // TODO add your handling code here:
        String n[] = {""};
        this.lista_diretor.setListData(n);
    }//GEN-LAST:event_adicionar_diretor1ActionPerformed

    private void adicionar_ator1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionar_ator1ActionPerformed
        // TODO add your handling code here:
        String n[] = {""};
        this.lista_ator.setListData(n);
    }//GEN-LAST:event_adicionar_ator1ActionPerformed

    private void adicionar_genero1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionar_genero1ActionPerformed
        // TODO add your handling code here:
        String n[] = {""};
        this.lista_genero.setListData(n);
    }//GEN-LAST:event_adicionar_genero1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AlterarFilme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AlterarFilme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AlterarFilme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AlterarFilme.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AlterarFilme().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton adicionar_ator;
    private javax.swing.JButton adicionar_ator1;
    private javax.swing.JButton adicionar_diretor;
    private javax.swing.JButton adicionar_diretor1;
    private javax.swing.JButton adicionar_genero;
    private javax.swing.JButton adicionar_genero1;
    private javax.swing.JTextField ano_lancamento;
    private javax.swing.JComboBox ator;
    private javax.swing.JComboBox categoria;
    private javax.swing.JComboBox diretor;
    private javax.swing.JTextField duracao;
    private javax.swing.JComboBox genero;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JList lista_ator;
    private javax.swing.JList lista_diretor;
    private javax.swing.JList lista_genero;
    private javax.swing.JTextField nome;
    private javax.swing.JTextArea sinopse;
    private javax.swing.JTextField traducao;
    // End of variables declaration//GEN-END:variables
}
